import request from '@/utils/request'
import { ApiModulesRoutes } from '@/consts'

/**
 * 分页查询分组列表
 * @param paramVo
 * @param paramVo.pageNo 页码
 * @param paramVo.pageSize 页大小
 * @returns {Promise<AxiosResponse<any>>}
 */
export const apiFindGroupPageByParam = async paramVo => {
  const url = ApiModulesRoutes.IOT + '/gateway/findGroupPageByParam'
  return request.post(url, paramVo)
}

/**
 *
 * @param {Object} groupVo
 * @param {String} groupVo.name 分组名
 * @param {String} groupVo.remark 备注名
 * @returns {Promise<void>}
 */
export const apiAddGroup = async groupVo => {
  const url = ApiModulesRoutes.IOT + '/gateway/addGroup'
  return await request.post(url, groupVo)
}

/**
 * 获取分组详情
 * @param {String} groupId 分组id
 * @returns {Promise<void>}
 */
export const apiFindGroupById = async groupId => {
  const url = ApiModulesRoutes.IOT + '/gateway/findGroupById'
  return await request.get(url, { params: { groupId } })
}

/**
 * 修改分组
 * @param {Object} groupVo
 * @param {String} groupVo.id 分组id
 * @param {String} groupVo.name 分组名
 * @param {String} groupVo.remark 分组备注
 * @returns {Promise<AxiosResponse<any>>}
 */
export const apiUpdateGroup = async groupVo => {
  const url = ApiModulesRoutes.IOT + '/gateway/updateGroup'
  return await request.post(url, groupVo)
}

/**
 * 删除指定分组
 * @param {String} groupId 分组id
 * @returns {Promise<AxiosResponse<any>>}
 */
export const apiDelGroupById = async groupId => {
  const url = ApiModulesRoutes.IOT + '/gateway/delGroupById'
  return await request.get(url, { params: { groupId } })
}

/**
 * 添加设备分组关系
 * @param {Array} groupDeviceVos
 * @param {String} groupDeviceVos.deviceId 设备id
 * @param {String} groupDeviceVos.groupId 分组idd
 * @returns {Promise<AxiosResponse<any>>}
 */
export const apiAddGroupDevice = async groupDeviceVos => {
  const url = ApiModulesRoutes.IOT + '/gateway/addGroupDevice'
  return await request.post(url, groupDeviceVos)
}

/**
 * 删除设备分组关系
 * @param  {Object} groupDeviceVo
 * @param {String} groupDeviceVo.deviceId 设备id
 * @param {String} groupDeviceVo.groupId 分组idd
 * @returns {Promise<void>}
 */
export const apiDelGroupDevice = async groupDeviceVo => {
  const url = ApiModulesRoutes.IOT + '/gateway/delGroupDevice'
  return await request.post(url, groupDeviceVo)
}
